package com.lhwl.it.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 系统常量
 * @author
 *
 */

@SuppressWarnings("unchecked")
@Component
public class Xtcl {

	/**
	 * 系统常量列表
	 */
	public static List<Map> xtclList;

	private static SqlSession sqlSession;
	
	@Autowired
	public Xtcl(SqlSession sqlSession){
		this.sqlSession = sqlSession;
		xtclInstance();
	}
	
	public void xtclInstance(){
		if(xtclList == null || xtclList.size() == 0){
			xtclList = sqlSession.selectList("CommonMapper.findAll", new HashMap());
		}
	}
	
	/**
	 * 根据常量类型获取系统常量信息
	 * @param cllx
	 * @return
	 */
	public static List getList(String cllx){
		if(cllx == null || "".equals(cllx)){  
			return null;
		}
		List rsList = new ArrayList();
		for(Map m:xtclList){
			String cs = (String)m.get("cllx");
			if(cllx.equalsIgnoreCase(cs)){
				rsList.add(m);
			}
		}
		return rsList;
	}
	
	/**
	 * 根据ID获取系统常量信息
	 * @param id
	 * @return
	 */
	public static Map getById(String id){
		if(id == null || "".equals(id)){
			return null;
		}
		for(Map m:xtclList){
			if(id.equalsIgnoreCase(m.get("id").toString())){
				return m;
			}
		}
		return null;
	}
	
	/**
	 * 获取所有的系统常量列表
	 * @return
	 */
	public static Object getAll(){
		return xtclList;
	}
	
	public static List getClmc(){
		List clmc = sqlSession.selectList("CommonMapper.getClmc",new HashMap());
		return clmc;
	}
	
}
